package com.tanhua.server.controller;

import com.tanhua.domain.db.Settings;
import com.tanhua.server.service.SettingsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
@Slf4j
public class SettingsController {

    @Autowired
    private SettingsService settingsService;


    /**
     * 接口名称：用户通用设置
     接口路径：GET/users/settings
     */
    @GetMapping("/settings")
    public ResponseEntity settings(){
        return settingsService.querySettings();
    }


    /**
     *接口名称：通知设置 - 保存
     接口路径：POST/users/notifications/setting
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity saveNotifications(@RequestBody  Settings settings){
        return settingsService.saveNotification(settings);
    }


    /**
     *接口名称：设置陌生人问题 - 保存
     *接口路径：POST/users/questions
     */
    @PostMapping("/questions")
    public ResponseEntity saveQuestion(@RequestBody Map<String,String> param){
        String content = param.get("content");
        return settingsService.saveQuestion(content);
    }


    /**
     *接口名称：黑名单 - 翻页列表
     接口路径：GET/users/blacklist
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize){
        return settingsService.blacklist(page,pagesize);
    }

    /**
     *接口名称：黑名单 - 移除
     接口路径：DELETE/users/blacklist/:uid
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackUser(@PathVariable("uid") Long blackUserId){
        return settingsService.deleteBlackUser(blackUserId);
    }


    @PostMapping("/phone/sendVerificationCode")
    //修改手机号【验证码发送】
    public ResponseEntity<Object> sendVerificationCode(){
        return settingsService.sendVerificationCode();
    }

    @PostMapping("/phone/checkVerificationCode")
    //校验验证码
    public ResponseEntity<Object> checkVerificationCode(@RequestBody Map<String,String> params){
        String verificationCode = params.get("verificationCode");
        return settingsService.checkVerificationCode(verificationCode);
    }

    @PostMapping("/phone")
    //更新手机号
    public ResponseEntity<Object> phone(@RequestBody Map<String,String> params){
        String phone = params.get("phone");
        return settingsService.updatePhone(phone);
    }

}
